/*  话题标签卡  */
$(function(){	
	//关闭登陆
	$(".modal .close").off("click").on("click",function () {
		$("#login-modal").hide();
		$("#signup-modal").hide();
		$(".modal-backdrop").hide();
	});
	
	//关注/取消关注此话题
	$("#cardIsCareDiv").off("click").on("click", function () {
		var attId = $("#cardTopicId").val();
		var status = $("#cardTopicStatus").val();
		if(getSessionUserId() != '') {
			if(status != "true") {
				//加关注
				careTopicEventCount(true,$("#topicTitle").html());
				$.post(getContextPath()+"settings/addCare?topicId="+attId, function(result){
					if (result.successMsg){
						$("#cardTopicStatus").val("true");
						$("#cardIsCareDiv").html("取消关注");
						$("#cardIsCareDiv").removeClass();
						$("#cardIsCareDiv").addClass("hf btn btn-attention2_1");
						var careCount = $("#careCount").text();
						$("#careCount").text(parseInt(careCount)+1);
					} else {
						swal("加关注", result.errorMsg, "error");
					}
				},'json');
			} else {
				//取消关注
				careTopicEventCount(false,$("#topicTitle").html());
				$.post(getContextPath()+"settings/cancelCare?topicId="+attId, function(result){
					if (result.successMsg){
						$("#cardTopicStatus").val("");
						$("#cardIsCareDiv").html("<i>+</i>关注");
						$("#cardIsCareDiv").removeClass();
						$("#cardIsCareDiv").addClass("hf btn btn-attention2");
						var careCount = $("#careCount").text();
						$("#careCount").text(parseInt(careCount)-1);
					} else {
						swal("取消关注", result.errorMsg, "error");
					}
				},'json');
			}
		} else {
			showLogin();
			return;
		}    
    });
	//初始化标签卡
	function initTopicCard(id) {
		$.post(getContextPath() + "topic/layer", {id: id}, function(data) {
			if(data.rscode == "1"){
				$("#bgImage").css("background-image", "url("+data.topic.topicImg+")");
				$("#topicImg").attr("src",data.topic.topicPhoto);
				$("#topicImg").css("width","85px;height:85px");
				$("#topicImg").css("border-radius","100%");
				$("#topicTitle").html(data.topic.topicName);
				$("#topicRemak").html(data.topic.topicRemark);
				$("#cardTopicId").val(data.topic.id);
				$("#cardTopicStatus").val(data.isCare);
				if(data.isCare == 'true') {
					$("#cardIsCareDiv").html("取消关注");
					$("#cardIsCareDiv").removeClass();
					$("#cardIsCareDiv").addClass("hf btn btn-attention2_1");
				} else {
					$("#cardIsCareDiv").html("<i>+</i>关注");
					$("#cardIsCareDiv").removeClass();
					$("#cardIsCareDiv").addClass("hf btn btn-attention2");
				}
				if(undefined != data.topic.topicRemark && data.topic.topicRemark.length > 38) {
					$("#topicRemak").html(data.topic.topicRemark.substr(0,37) + '...');
				}			
				$("#articleCount").html(data.articleCount);
				$("#careCount").html(data.topicCareCount);
				topicPVCount();
			}
		});
	}
	//标签卡事件
	var mouseCtl;
	var $popup_tag = $('.hua_list');
	var $btn = $('.hua a[data-role=webTopic]');
	var _topicId = "";
$btn.off('mouseenter').on('mouseenter', function(e){
		var $self = $(this);
		var offset = $self.offset();
		$popup_tag.css({
			top: offset.top,
			left: offset.left
		});
		topicPVCount();
		_topicId = $(this).attr('data-id');
		initTopicCard(_topicId);
		$popup_tag.show();
		clearTimeout(mouseCtl);
	});
	$btn.off("mouseleave").on('mouseleave', function(e){
		mouseCtl = setTimeout(function(){
		$popup_tag.hide();
		}, 100);
	});
	$popup_tag.off('mouseenter').on('mouseenter', function(e){
		clearTimeout(mouseCtl);
	});
	$popup_tag.off('mouseleave').on('mouseleave', function(e){
		$popup_tag.hide();
	});
	$('.hua_top').off('click').on('click', function(e){
		var _url = getContextPath()+'topic?id='+_topicId;
		window.open(_url);
	});
//	scroll-fixed-menu
	$(document).scroll(function(){
	    var scrollMenu = $(document).scrollTop();
	    if(scrollMenu >= 70){
	        $('.content').addClass('fixed-menu');
	    }
	    else{
	        $('.content').removeClass('fixed-menu');
	    }
	});
	
	//导航当前状态
	function navActive(){
		if($(window).width()>767){		
			var navArr=["index","university","major","study","interview","policy","pc","tzy","download"];
			var oA=$(".venus-menu").children("li").children("a");
			var currentNav=window.location.pathname.substr(1);
			
			if(navArr.length!=oA.length) return;
			
			for(var i=0;i<navArr.length;i++){
				navArr.index=i;
				if(currentNav==navArr[i]){		
					$(oA[navArr.index]).css({"background":"#ef5e23"});
				}
			}
		}	
	}
	navActive();
	
});

